import logging
import os

import pyautogui

from src.handler.hongbao import HongBaoConfig
from src.handler.hongbao.AbstractProcess import AbstractProcess
from src.utils import PyautoguiUtils


class TecentQiangHongBaoProcess(AbstractProcess):
    def __init__(self, config, config_dict):
        super().__init__(config, config_dict)
        self.config = config
        self.config_dict = config_dict

    def check(self) -> dict:
        sub_image_path = os.path.join(self.config.resource_path(), "qiang_hong_bao.png")
        save_path = HongBaoConfig.get_config_dir_file("cap_qiang_hong_bao.png")
        result = PyautoguiUtils.find_image_position(sub_image_path, 668, 540, 535, 260, save_path=save_path)
        found = result["found"]
        result["check"] = found
        return result

    def do_process(self, check_result: dict):
        logging.info(f"发现坐标x:{check_result['x']} y:{check_result['y']}")
        pyautogui.moveTo(check_result['x'], check_result['y'], duration=1)
        pyautogui.click(check_result['x'], check_result['y'])
        return True
